/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package G3.Mod;

import android.os.Environment;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.ArrayList;

/**
 * a lot of this code isn't proper yet and not done, but it's functinal and I'll fix it asap
 * @author Dymion
 */
public class writefile {

    /**
     * The default empty constructor
     */
    public writefile() {
        //the empty constructor, we do nothing here.
    }

    /**
     * The constructor with a String variable
     * @param item = The single line we write to a file
     */
    public writefile(String item, String location, String filename, boolean sd) {
        try {
            File folder;
            if (sd) {
                folder = new File(Environment.getExternalStorageDirectory() + location);
            } else {
                folder = new File(location);
            }
            folder.mkdir();

            FileOutputStream fOut = new FileOutputStream(new File(folder, filename));
            OutputStreamWriter osw = new OutputStreamWriter(fOut);

            osw.write(item);

            osw.flush();
            osw.close();
        } catch (IOException ex) {
            //do nothing
        }
    }

    /**
     * The constructor of writefile with an ArrayList variable
     * @param items = An arraylist of String which contains all the needed lines we'll write to the file.
     */
    public writefile(ArrayList<String> items, String location, String filename, boolean sd) {
        try {
            File folder;
            if (sd) {
                folder = new File(Environment.getExternalStorageDirectory() + location);
            } else {
                folder = new File(location);
            }
            folder.mkdir();

            FileOutputStream fOut = new FileOutputStream(new File(folder, filename));
            OutputStreamWriter osw = new OutputStreamWriter(fOut);

            for (int i = 0; i < items.size(); i++) {
                osw.write(items.get(i));
            }

            osw.flush();
            osw.close();
        } catch (IOException ex) {
            //do nothing
        }
    }
}
